<template>
    <div class="edit">
        <h3 style='text-align:center;font-weight:700;margin:10px'>编辑互联网收费项目</h3>
        <div class="main">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="90" label-position="left">
                <Row gutter="32" class="infobox">
                    <p class="title">项目基本信息</p>
                    <Col span="8">
                        <FormItem prop="projectCategory" label="项目类别：">
                            <span>{{formValidate.projectCategory}}</span>
                        </FormItem>
                        <FormItem label="组合名称：" prop="name">
                            <Input v-model="formValidate.name" :maxlength="50" placeholder="输入项目名称" style='width:100%;'></Input>
                        </FormItem>
                        <FormItem prop="chargingUnit" label="项目收费单位：" :label-width="110">
                            <Select v-model="formValidate.chargingUnit" style='width:100%;'>
                                <Option style='text-align:center;' :value="item.id" :key='item.id' v-for='item in chargingUnit'>{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="项目物价码：" class="hongdian">
                            <Input v-model="formValidate.priceCode" :maxlength="120" placeholder="输入项目物价码" style='width:100%;'></Input>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem prop="classify" label="项目分类：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' " style='width:100%;'>
                            <Select v-model="formValidate.classify" 
                             @click='getClassificationList(0)' style='width:70%;'>
                                <Option
                                    v-for="item in classificationList"
                                    :value="item.id"
                                    :key="item.id"
                                    :label='item.typeName'
                                    style='text-align:center'
                                >{{item.typeName}}</Option>
                            </Select>
                            &nbsp;&nbsp;
                            <Button type='primary' @click="addClassification">
                                <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                            </Button>
                        </FormItem>
                        <FormItem label="执行科室：" class="hongdian">
                            <Select v-model="formValidate.executiveDeptId"  style='width:100%;'>
                                <Option
                                    v-for="item in departmentList"
                                    :value="item.id"
                                    :key="item.id"
                                    style='text-align:center'
                                >{{item.deptNickname}}</Option>
                                <!-- dictName -->
                            </Select>
                        </FormItem>
                        <FormItem prop="priceBasis" label="项目平台收费标准（元）：" :label-width="170">
                            <InputNumber :max="9999" :min="0" v-model="formValidate.priceBasis" placeholder="0.00" style='width:100%;'></InputNumber>
                        </FormItem>
                    </Col>
                    <Col span="8"> 
                        <FormItem prop="position" label="默认部位/标本类：" :label-width="140" style='width:100%;'>
                            <Select v-model="formValidate.position"  style='width:66%;'  @click='getClassificationList(1)'>
                                <Option
                                    v-for="item in specimen"
                                    :value="item.id"
                                    :key="item.id"
                                    :label='item.typeName'
                                    style='text-align:center'
                                >{{item.typeName}}</Option>
                            </Select>
                            &nbsp;&nbsp;
                            <Button type='primary' @click="addposition">
                                <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                            </Button>
                        </FormItem>
                        <FormItem label="组合规格：" class="hongdian">
                            <Input v-model="formValidate.norms" :maxlength="120" placeholder="输入项目规格" style='width:100%;'></Input>
                        </FormItem>
                        <FormItem label="项目收费依据：" :label-width="110" class="hongdian">
                            <Input v-model="formValidate.charge" :maxlength="50" placeholder="输入收费依据" style='width:100;'></Input>
                        </FormItem>
                    </Col>
                    <Col span="15">
                        <Row>
                            <Col span="8">
                                <FormItem label="启用标识：" class="hongdian">
                                    <iSwitch size="large" v-model="formValidate.status" @on-change="changeStatus(formValidate.status)">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="是否为预约项：" :label-width="100">
                                    <iSwitch size="large" v-model="formValidate.isubscribe" @on-change="changeisubscribe(formValidate.isubscribe)" :disabled="isubscribeDisable">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="患者可否直接预约：" :label-width="120">
                                    <iSwitch size="large" v-model="formValidate.ipatientAppointment" :disabled="ipatientAppointmentDisable">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                </FormItem>
                            </Col>                         
                        </Row>      
                    </Col>
                    <Col span="24">
                        <FormItem label="备注说明：" class="hongdian">
                            <Input v-model="formValidate.reason" :maxlength="500" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入备注"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row gutter="32" class="infobox">
                    <p class="title">院内系统项目关联</p>
                    <div class="hongdian">
                        <span class="tit">添加项目：</span>
                        <Input v-model.trim="xmmc" placeholder="请输入项目名称检索" style="width: 200px;margin-left:10px;margin-right:10px"></Input>
                        <Button type="primary" icon="ios-search" @click='pageChangexm(1)'>查询</Button>
                    </div>
                    <div class = 'footerList'>
                        <div class="left">
                            <p>可选项目</p>                  
                            <Table stripe :columns="columns2" :data="data2"></Table>
                            <Page :total="total"  :page-size='pageSize' :current = 'pageNo' style='margin:10px 0;text-align: center;' @on-change='pageChangexm'/>
                        </div>      
                        <div class="right">                       
                            <p>已选项目</p>
                            <Table stripe :columns="columns3" :data="data3" ref="table3">
                                <template slot="num" slot-scope="props" >                              
                                    <InputNumber v-model="props.row.num" @on-change='money' placeholder="输入数量" :min='1' :max="999" :rules="{required:true , message: '请输入关联数量', trigger: 'change'}"></InputNumber>                             
                                </template>
                            </Table>                      
                            <p v-if="this.data3.length" style="border:1px solid #ccc;border-top:none; border-bottom:none;font-size: 14px; padding-left: 200px;">总计：<span>{{zj}}&nbsp;&nbsp;元</span></p>
                        </div>                    
                    </div> 
                </Row>
            </Form>
            <div style='textAlign: center;'>
                <Button type='primary' @click='handleSubmit("formValidate")' :disabled="isDisable" style="width:95px;height:35px;">
                    <Icon type="ios-checkmark" style="margin-right: 5px" />确认修改
                </Button>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <Button @click='handleReset("formValidate")' style="width:75px;height:35px;">
                    <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                </Button>
            </div>
            <Modal
                v-model = "modalStatus1"
                width='1000'
                :styles="{height: '100px'}"
                :closable='false'
                :mask-closable="false"
                footer-hide>   
                <h3 style='text-align:center;font-weight:700;margin:10px'>{{whtitle}}</h3>  
                <div style="height:40px">
                    <Button type='info' :disabled="isDisable" @click="add(data1)">
                        <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>新增
                    </Button>           
                    <span style="color:#ff9966;margin-left:20px">( 提示：每次只可新增一条 )</span>   
                </div>
                <Table ref="myTable" @on-selection-change="selectChange" :loading="tableLoading" border stripe :columns="columns1" :data="data1" height="600">
                    <template slot="inspection" slot-scope="props">
                        <span>{{ props.row.inspection }}</span>
                    </template>
                    <template slot="typeName" slot-scope="props" >
                        <Input v-model="props.row.typeName" placeholder="请输入分类名称" v-if="editIndex == props.idx || bc == '1'" maxlength="50"></Input>
                        <span v-else>{{ props.row.typeName }}</span>
                    </template>
                     <template slot="sort" slot-scope="props" >
                        <InputNumber v-model="props.row.sort" placeholder="请输入排序" v-if="editIndex == props.idx || bc == '1'" :max='999999' :min='0'></InputNumber>
                        <span v-else>{{ props.row.sort }}</span>
                    </template>
                     <template slot="relatingCodes" slot-scope="props" >
                        <Input v-model="props.row.relatingCodes" placeholder="请输入关联码" v-if="editIndex == props.idx || bc == '1'" maxlength="6"></Input>
                        <span v-else>{{ props.row.relatingCodes }}</span>
                    </template>
                     <!-- 操作 -->
                    <template slot="idel" slot-scope="props" >
                        <div v-if="editIndex == props.idx">
                            <Button @click="editsub(data1,props.idx)" type='primary' size="small">
                                <Icon type="ios-checkmark" style="margin-right: 5px" />保存
                            </Button>
                            <Button @click="editIndex = -1">
                                <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                            </Button>
                        </div>
                        <div v-if="editIndex != props.idx && bj !='1' ">
                            <Button  type='primary' size="small"  @click="handleEdit(row,props.idx)">
                                <i class = "iconfont icon-bianji" style="font-size:14px;margin-right:5px"></i>编辑
                            </Button>
                        </div>
                        <div v-if="bc =='1' ">
                            <Button  type='primary' size="small"  @click="sub(data1,props.idx)">
                                <Icon type="ios-checkmark" style="margin-right: 5px" />保存
                            </Button>
                        </div>                   
                    </template>
                </Table> 
                <div style='textAlign: center;margin:10px'>
                    <Button @click='back'>
                        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                    </Button>
                </div>
            </Modal>
        </div>
    </div>
</template>
<script>
import api from "@/api/commonApi";
export default {
    data(){
        return{
            hospitalId: sessionStorage.getItem("hospitalId"),
            isBack: 2,
            id: '',
            isDisable: false,//表单重复提交
            isubscribeDisable: false,//禁止预约项点击
            ipatientAppointmentDisable: false,//禁止患者预约项点击
            moldType: '',
            zj:0,
            projectStatus: null,
            // 项目类型列表
            projectCategoryList: [           
                {
                    name:"检查项目",
                    id:'3'
                },
                {
                    name:"检验项目",
                    id:'4'
                },
                {
                    name:"治疗项目",
                    id:'5'
                },
                {
                    name:"其他",
                    id:'6'
                },
            ],
            Name: "",
            // 分页数据
            count: 10,
            pageNo: 1,
            pageSize: 10,
            // 弹出窗状态
            modalStatus1: false,
            modalStatus2: false,
            modalStatus3: false,                     
            sclxList:[],
            tab: '1',
            bc:'',
            bj: '',
            type: '',
            editIndex: -1,
            inspection: '',
            typeName: '',
            sort: '',
            relatingCodes: '',
            columns1: [
                {
                    title: '编码排序',
                    key: 'sum',
                    align: "center",
                    width: 90,
                },
                {
                    key: "inspection",
                    title: "上级分类",
                    align: "center",
                    render: (h, params) => {
                        this.data1[params.index] = params.row
                        let inspection = params.row.inspection;
                        switch (inspection) {
                            case 1:
                                return "健康咨询";
                            case 2:
                                return "巡诊";
                            case 3:
                                return "检查项目";
                            case 4:
                                return "检验项目";
                            case 5:
                                return "治疗项目";
                            case 6:
                                return "其他";
                        }        
                        if(this.tab == '1' && this.type == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.inspection({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }

                },
                {
                    title: '分类名称',
                    key: 'typeName',
                    align: "center",
                    render: (h, params) => {
                        this.data1[params.index] = params.row
                        let typeName = params.row.typeName;
                        if(this.tab != '1' ){
                            switch (typeName) {
                                case typeName:
                                return typeName;
                            }       
                        }
                         
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.typeName({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '排序',
                    key: 'sort',
                    align: "center",
                    render: (h, params) => {
                        this.data1[params.index] = params.row
                        let sort = params.row.sort;
                        if(this.tab != '1'){
                            switch (sort) {
                                case sort:
                                return sort;
                            }       
                        }
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.sort({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '关联码',
                    key: 'relatingCodes',
                    align: "center",
                    render: (h, params) => {
                        this.data1[params.index] = params.row
                        let relatingCodes = params.row.relatingCodes;
                        if(this.tab != '1'){
                            switch (relatingCodes) {
                                case relatingCodes:
                                return relatingCodes;
                            }       
                        }
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.relatingCodes({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '设置',
                    key: 'idel',
                    align: "center",
                    render: (h, params) => {
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.idel({
                                    idx: params.row._index
                                })
                            )                       
                    }
                }
            ],
            data1:[],
            // 左侧医疗团队成员
            columns2:[
                {
                    title:"排序",
                    align:"center",
                    key:"sum",
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    title:"项目名称",
                    align:"center",
                    key:"itemName"
                },
                {
                    title:"单价",
                    align:"center",
                    key:"chargingPrice"
                },
                {
                    title:"设置",
                    align:"center",
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('a', {
                                on:{
                                    'click':() => {
                                        let flag = false;
                                        if(this.data3.length) {
                                            this.data3.forEach((item,index) => {
                                                if(row.id == item.id){
                                                    flag = true;
                                                }  
                                            })
                                        }
                                        if(flag){
                                            this.$Message.error("请勿重复添加");
                                            return;
                                        }
                                        row.num = 1
                                        this.data3.push(row)
                                        this.data3.forEach((item,index) => {
                                            // 排序
                                            item.sum = this.addZeros(index)
                                        })
                                        this.data2.splice(row._index,1);
                                        this.money()
                                    }
                                }
                            }, '添加')
                        ]
                    }
                }
            ],
            total: '',
            data2:[],
            dataYX:[],
            // 右侧医疗团队成员
            columns3:[
                {
                    title:"排序",
                    align:"center",
                    key:"sum"
                },
                {
                    title:"项目名称",
                    align:"center",
                    key:"itemName"
                },
                {
                    title:"单价",
                    align:"center",
                    key:"chargingPrice"
                },
                {
                    key: "num",
                    title: "数量",
                    align: "center",
                    render:(h,params) => {
                        this.data3[params.index] = params.row
                             return [                          
                                h('div', 
                                    this.$refs.table3.$scopedSlots.num({
                                        row: params.row,
                                        idx: params.row._index
                                    
                                    })
                                )
                            ]                         
                    }
                },
                {
                    title:"设置",
                    align:"center",
                    key:"sum",
                    render:(h,params) => {
                        let row = params.row
                        return [
                            h('a',{
                                on:{
                                    'click':() => {
                                        row.role = ''
                                        this.data3.splice(row._index,1)
                                        this.money()
                                        this.data2.push(row)
                                        this.roleList[0].disabled = this.disabledRole()
                                    }
                                }
                            },'移除')
                        ]
                    }
                }
            ],
            data3:[],
            xmmc: '',
            // 表单验证以及项目详细数据
            formValidate: {
                // 项目类型
                projectCategory: "",
                //项目分类
                itemType: '',
                //执行科室
                executiveDept: "",
                executiveDeptId: "",
                // 职称
                title: "",
                // 项目名称
                name: "",
                //检查部位,标本类型
                position: "",
                // 项目规格               
                norms: "",
                // 物价码
                priceCode: "",
                // 收费依据
                chargetrue: "",
                // 收费单位
                chargingUnit: "",
                // 收费依据
                priceBasis: "",
                // 备注
                reason: "",
                // 业务模块
                modular: "",
                // 启用标识
                status: true,
                itemUsed: true,
                // 标识Id
                id: "",
                // 医院ID
                hospitalId: sessionStorage.getItem("hospitalId"),
                //是否为预约项
                isubscribe: "",
                //是否患者可以直接预约
                ipatientAppointment: "",
                //对应HIS项目
          
            },
            ruleValidate: {
                projectCategory: [{ required: true, message: '请选择项目', trigger: 'change' }],
                classify: [{ required: true, message: '请选择项目分类', trigger: 'change' }],
                position: [{ required: true, message: '请选择检查部位/标本类型', trigger: 'change' }],
                name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
                chargingUnit: [{ required: true, message: '请选择收费单位', trigger: 'change' }],
                priceBasis: [{ required: true, message: '请输入收费单价', trigger: 'blur', type:'number' }],
                modular: [{ required: true, message: '请选择项目', trigger: 'change', type:'number'}],
            },           
            //项目分类列表
            classificationList: [],
            //默认检查部位/标本类
            specimen:[],
            //执行科室列表
            departmentList: [],
            // 职称列表
            titleList: [],
            // 收费单位列表
            chargingUnit: [],
            //标本类列表
            specimenList: [],
            // 业务模块
            modular: [],
            Allmodular: ["健康咨询","问诊","复诊","续方","用药咨询"],
            buttonName: "确认添加",
            whtitle: '项目分类维护',
        }
    },
    created() {
        this.hospitalId = parseInt(this.$route.query.hospitalId);
        this.id = this.$route.query.id;
        this.pageNo = this.$route.query.pageNo?parseInt(this.$route.query.pageNo):1;     
        this.getdetail();
    },
    mounted () {
        // 页面查询的科室选择框
        this.loadingDepartment()
        //获取HIS收费项目
        this.getHisPage()
    },
    methods:{
        //计算总价
        money(){
            this.zj = 0
            if (this.data3 && this.data3.length ) {               
                this.data3.map(item => {     
                     if(item.num){
                        this.zj += Number(item.chargingPrice)*Number(item.num)
                     }           
                })
            }
            this.zj = this.zj.toFixed(2);
        },
        //是否启用控制其他俩个按扭的状态
        changeStatus(val){
            if(val == false){
                this.formValidate.isubscribe =  false
                this.formValidate.ipatientAppointment = false
                this.isubscribeDisable = true
                this.ipatientAppointmentDisable = true              
            } else {
                this.isubscribeDisable = false           
            }
        },
        changeisubscribe(val){
            if(val == false){
                this.formValidate.ipatientAppointment = false
                this.ipatientAppointmentDisable = true               
            } else {
                this.ipatientAppointmentDisable = false
            }
        },
         //表格
        selectChange(selections) {
            this.selections = selections;
        },
        // 根据项目类型切换不同的业务模块
        projectCategoryChange () {
            this.formValidate.modular = ''
            this.getClassificationList();
        },
        disabledRole(){
            return this.data3.some(item =>{
                return parseInt(item.role) == 1
            })
        },
         // 页面查询的科室选择框 
        loadingDepartment(){
            let url = api.findDeptName
            let params = {
                hospitalId : this.hospitalId,
                medicalTechnology: 1
            }
            this.packageAxios(this,url,params,(res)=>{
                console.log(res);
                if(res.data.success) {
                    let ret = res.data.object;                   
                    this.departmentList = ret;
                } else {
                    this.$Message.error("加载失败")
                }
            })
        },
         // 加载收费列表
         getfeeunitenum(){
              this.$axios.post(api.findFeeEnum,{}).then(resp => {
                if(resp.data.success) {
                    let ret = resp.data;
                    this.chargingUnit = ret.object;
                    console.log(this.chargingUnit)
                }
            })
         },
        //获取单项项目
        getHisPage(){
            let inspection
            if(this.formValidate.projectCategory == "检查项目"){
                 inspection = 3
            } else if(this.formValidate.projectCategory == "检验项目"){
                 inspection = 4
            } else if(this.formValidate.projectCategory == "治疗项目"){
                 inspection = 5
            } else if(this.formValidate.projectCategory == "手术项目"){
                 inspection = 6
            } else if(this.formValidate.projectCategory == "体检项目"){
                 inspection = 7
            } else {
                 inspection = 8
            }                 
            let params = {
                "hospitalId": this.hospitalId,
                "pageNo": this.pageNo,
                "pageSize": this.pageSize,   
                "inspection": inspection,
                "combinationType": 1                 
            }
            if (this.xmmc != "") {
                params.itemName = this.xmmc.trim();
            }
            this.$axios
                .post(api.findMedicalCombination, params)
                .then(resp => {
                    let ret = resp.data.object.records;
                    ret.forEach((item,index) => {
                        // 排序
                        item.sum = this.addZeros(index)
                    })
                    this.data2 = ret
                    this.total = resp.data.object.total
                    // console.log('获取单项项目',this.data2)
                    // console.log('已选项目',this.data3)
                    // console.log(this.dataYX)
                    // if(this.data3.length) {
                    //     this.data3.forEach((item,index) => {
                    //         this.dataYX = []
                    //         this.data2.forEach((i,index) => {
                    //             if(item.id != i.id){
                    //                 this.dataYX.push(i)
                    //             }
                    //             console.log(this.dataYX)
                    //         })
                    //     })
                    // }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //获取详情
        getdetail(){
            this.getfeeunitenum()
            this.$axios.post(api.findCombinationById, {
                "hospitalId": this.hospitalId,
                "combinationId": this.id,
                "combinationType": 1,
            }).then(res => {
                if(res.data.success) {
                    console.log(res.data.object)
                    let ret = res.data.object.dhtboMedicalTechnologyCombination;
                    let pop
                    if(res.data.object.list){
                        pop = res.data.object.list;
                        this.data3 = pop.map((i,index)=>({
                            itemName : i.techName,
                            num: i.num,
                            chargingPrice: Number(i.chargingPrice),
                            sum: this.addZeros(index),
                            combinationType: 1,
                            id: i.chargeId,
                        }))   
                         //计算总价 
                         this.zj = 0
                         let zongjia = 0
                        if (this.data3 && this.data3.length) {
                            this.data3.forEach((item, index) => {
                                zongjia += Number(item.chargingPrice)*Number(item.num);
                            })
                        } 
                        this.zj = zongjia.toFixed(2)
                    }               
                    if(ret.inspection == 3){
                        this.formValidate.projectCategory = "检查项目"
                    } else if(ret.inspection == 4){
                        this.formValidate.projectCategory = "检验项目"
                    } else if(ret.inspection == 5){
                        this.formValidate.projectCategory = "治疗项目"
                    } else if(ret.inspection == 6){
                        this.formValidate.projectCategory = "手术项目"
                    } else if(ret.inspection == 7){
                        this.formValidate.projectCategory = "体检项目"
                    } else {
                        this.formValidate.projectCategory = "其他"
                    }                        
                    this.formValidate.classify = ret.classify;
                    this.formValidate.charge = ret.chargingBasis	;
                    this.formValidate.priceCode = ret.priceCode
                    this.formValidate.priceBasis = ret.chargingPrice
                    this.formValidate.chargingUnit = ret.chargingUnit
                    this.formValidate.executiveDept = ret.executiveDept
                    this.formValidate.executiveDeptId = ret.executiveDeptId
                    this.formValidate.name = ret.techName;
                    this.formValidate.position = ret.position;
                    this.formValidate.norms = ret.specifications
                    this.formValidate.status = Boolean(Number(ret.ienable))
                    this.formValidate.ipatientAppointment = Boolean(Number(ret.ipatientAppointment))
                    this.formValidate.isubscribe = Boolean(Number(ret.isubscribe))
                    this.formValidate.reason = ret.remarks
                    this.formValidate.id = ret.id
                    this.formValidate.consultationForm = ret.consultationForm
                    if(this.formValidate.status == false ){
                        this.formValidate.isubscribe = false
                        this.isubscribeDisable = true   
                    }
                    if(this.formValidate.isubscribe == false){
                        this.formValidate.ipatientAppointment = false
                        this.ipatientAppointmentDisable = true   
                    }
                    if(this.formValidate.classify){
                        this.getClassificationList(0)
                    }
                    if(this.formValidate.position){
                        this.getClassificationList(1)
                    }
                } else {
                    this.$Message.error("加载项目详情失败")
                }
            })
        },
        // 修改后保存
        handleSubmit (name) {
            this.isDisable = true  //不可点击
            this.$refs[name].validate((valid) => {
                if (valid) {
                    if(String(this.formValidate.priceBasis).indexOf('.')!=-1 && String(this.formValidate.priceBasis).split('.')[1].length>2){
                        this.$Message.error('项目平台收费标准请保留两位小数!');
                        this.isDisable = false  //不可点击
                        return;
                    }
                    let url = api.updateTechnologyCombination;
                    let inspection
                    if(this.formValidate.projectCategory == "检查项目"){
                        inspection = 3
                    } else if(this.formValidate.projectCategory == "检验项目"){
                        inspection = 4
                    } else if(this.formValidate.projectCategory == "治疗项目"){
                        inspection = 5
                    } else if (this.formValidate.projectCategory == "手术项目"){
                        inspection = 6
                    } else if (this.formValidate.projectCategory == "体检项目"){
                        inspection = 7
                    } else {
                        inspection = 8
                    }         
                    let medicalTechnologyCombination  = {
                        "hospitalId": this.formValidate.hospitalId,
                        "id": this.id,
                        "priceCode": this.formValidate.priceCode,
                        "chargingBasis": this.formValidate.charge,
                        "chargingPrice": this.formValidate.priceBasis,
                        "chargingUnit": this.formValidate.chargingUnit,
                        "techName": this.formValidate.name,
                        "specifications": this.formValidate.norms,
                        "inspection": inspection,
                        "ienable": Number(this.formValidate.status),
                        "ipatientAppointment": Number(this.formValidate.ipatientAppointment),
                        "isubscribe": Number(this.formValidate.isubscribe),
                        "remarks": this.formValidate.reason,                       
                        "classify": this.formValidate.classify,
                        "executiveDeptId": this.formValidate.executiveDeptId,
                        "position": this.formValidate.position,
                        "combinationType": 1,                     
                    }
                    this.chargingUnit.forEach(i => {
                        if(i.id == this.formValidate.chargingUnit){
                            medicalTechnologyCombination.itemFeeUnitName = i.name
                        }
                    })
                    if(this.formValidate.executiveDeptId){
                        this.departmentList.forEach(z => {
                            if(z.id == this.formValidate.executiveDeptId){
                                medicalTechnologyCombination.executiveDeptName = z.deptNickname
                                medicalTechnologyCombination.executiveDept = z.dictType
                            }
                        })    
                    }  
                    if(this.formValidate.classify){
                        this.classificationList.forEach(z => {
                            if(z.id == this.formValidate.classify){
                                medicalTechnologyCombination.classifyName = z.typeName
                            }
                        })    
                    }
                    if(this.formValidate.position){
                        this.specimen.forEach(z => {
                            if(z.id == this.formValidate.position){
                                medicalTechnologyCombination.positionName = z.typeName
                            }
                        })    
                    }                                       
                    let list = 
                        this.data3.map(i=>({
                            "chargeId": i.id,
                            "combinationType": 1,  
                            "num": i.num,
                        }))
                    let params = {
                        list,
                        medicalTechnologyCombination 
                    }
                    console.log("新增参数",params);
                    if(params.list.length == 0){
                        this.$Message.error('请选择院内系统关联项目')
                        setTimeout(() => {
                            this.isDisable = false;//放开点击了
                        }, 1000);
                    } else {
                        this.$axios.post(url, params).then(res => {
                            if(res.data.success) {
                                this.$Message.success('修改成功')
                                this.isDisable = false;//放开点击了
                                // 弹窗数据初始化
                                this.handleReset('formValidate');
                                this.modalStatus = false;
                            } else {
                                this.isDisable = false;//放开点击了
                                this.$Message.error(res.data.message)
                            }
                        }).catch(err => {
                            this.isDisable = false;//放开点击了
                            console.log(err);
                        });
                    }
                } else {
                    this.$Message.error('请完整填写必填项!');
                    this.isDisable = false  //不可点击
                }
            })
        },
        // 取消保存
        handleReset (name) {
            this.$refs[name].resetFields();
            this.formValidate.projectCategory = ''
            // 项目名称
            this.formValidate.name = ''
            // 项目规格
            this.formValidate.norms = ''
            // 物价码
            this.formValidate.priceCode = ''
            // 收费依据
            this.formValidate.charge = ''
            // 收费单位
            this.formValidate.chargingUnit = ''
            // 收费标准
            this.formValidate.priceBasis = ''
            // 备注
            this.formValidate.reason = ''
            //项目分类
            this.formValidate.classify = ''
            //执行科室
            this.formValidate.executiveDept = ''
            this.formValidate.executiveDeptId = ''
            //默认检查部位/标本类
            this.formValidate.position = ''
            // 业务模块
            this.formValidate.modular = ''
            // 启用标识
            this.formValidate.status = false
            this.formValidate.ipatientAppointment = false
            this.formValidate.isubscribe = false
            // 标识Id
            this.formValidate.id = ''
            this.modalStatus = false
            this.formValidate.consult = ''
             this.formValidate.consultPrice = ''
             let query = this.$route.query
            this.functionJS.queryNavgationTo(
                this,
                "/index/directory/priceManagement/index",
                {type:'2',hospitalId:this.hospitalId}
            );
            this.type = null
            this.tab = '2'
        },
        //获取项目分类列表
        getClassificationList (val) { 
            if(val == 0){
                this.whtitle = "项目分类维护"
            } else {
                this.whtitle = "默认部位/标本类型维护"
            }     
             let inspection
            if(this.formValidate.projectCategory == "检查项目"){
                 inspection = 3
            } else if(this.formValidate.projectCategory == "检验项目"){
                 inspection = 4
            } else if(this.formValidate.projectCategory == "治疗项目"){
                 inspection = 5
            } else if (this.formValidate.projectCategory == "手术项目"){
                inspection = 6
            } else if (this.formValidate.projectCategory == "体检项目"){
                inspection = 7
            }  else {
                 inspection = 8
            }                  
            let params = {
                "hospitalId": this.formValidate.hospitalId,              
                "inspection": inspection,
                "moldType": val,
                "idel": 0,
            }
            this.$axios
                .post(api.findMedicalTechnology, params)
                .then(resp => {
                    let ret
                    if(resp.data.object){
                        ret = resp.data.object
                        ret.forEach((item,index) => {
                            // 排序
                            item.sum = this.addZeros(index)
                        })  
                        if(val == 0){
                            this.classificationList = ret;    
                            this.data1 = this.classificationList
                            console.log('项目分类',this.classificationList)
                        } else {
                            this.specimen = ret
                            this.data1 = this.specimen
                            console.log('默认部位',this.specimen)
                        }                     
                    } else{
                        if(val == 0){
                            this.classificationList = [];    
                            this.data1 = []
                        } else {
                            this.specimen = []
                            this.data1 = []
                        }             
                    }    
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //添加项目分类
        addClassification(){
            this.modalStatus1 = true
            this.editIndex='-1'
            this.bj = ''
            this.bc = ''
            this.moldType = 0
            this.getClassificationList (0)
        },
        //添加默认检查部位/标本字典
        addposition(){
            this.modalStatus1 = true
            this.editIndex='-1'
            this.bj = ''
            this.bc = ''
            this.moldType = 1
            this.getClassificationList (1)
        },
        //编辑项目分类列表
        handleEdit (row, index) {
            this.editIndex = index;
            this.type = ''
        },
        //修改字典后保存
        editsub(val,index){
            let params = {
                "hospitalId": this.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    params.typeName= i.typeName
                    params.inspection = i.inspection
                    params.sort = i.sort
                    params.relatingCodes = i.relatingCodes
                    params.id = i.id
                    params.moldType = this.moldType
                }
            })
            if (params.inspection == "") {
                this.$Message.info("上级分类不能为空");
            } else if (params.typeName == "") {
                this.$Message.info("分类名称不能为空");
            } else if (params.sort == "") {
                this.$Message.info("排序不能为空");
            } else if (params.relatingCodes == "") {
                this.$Message.info("关联码不能为空");
            } else{
                this.$axios
                .post(api.updatetMedical, params)
                .then(resp => {
                    if(res.data.success){
                        this.$Message.success('保存成功')
                        let ret = resp.data.object;
                        console.log(ret)
                        this.getClassificationList(this.moldType)
                    }else {
                            this.isDisable = false;//放开点击了
                            this.$Message.error(res.data.message)
                        }                    
                })
                .catch(err => {
                    console.log(err);
                });
                this.editIndex = '-1';          
            }          
        },
        //保存新增字典
        sub(val,index){
            let params = {
                "hospitalId": this.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    let inspection
                    if(i.inspection == "检查项目"){
                        inspection = 3
                    } else if(i.inspection == "检验项目"){
                        inspection = 4
                    }  else if(i.inspection == "治疗项目"){
                        inspection = 5
                    }  else {
                        inspection = 6
                    }            
                    params.inspection = inspection
                    params.typeName= i.typeName
                    params.sort = i.sort
                    params.relatingCodes = i.relatingCodes
                    params.moldType = this.moldType
                }
            })
            if (params.inspection == "") {
                this.$Message.info("上级分类不能为空");
            } else if (params.typeName == "") {
                this.$Message.info("分类名称不能为空");
            } else if (params.sort == "") {
                this.$Message.info("排序不能为空");
            } else if (params.relatingCodes == "") {
                this.$Message.info("关联码不能为空");
            } else{
                this.$axios
                .post(api.insertMedical, params)
                .then(resp => {
                    if(resp.data.success){
                        console.log(params)
                        this.$Message.success('保存成功')
                        let ret = resp.data.object;
                        console.log(ret)
                        this.getClassificationList(this.moldType)
                    } else {
                            this.isDisable = false;//放开点击了
                            this.$Message.error(resp.data.message)
                        }                
                })
                .catch(err => {
                    console.log(err);
                }); 
                this.bc = ''
                this.bj ='1'
                this.editIndex = '-1';     
            }          
        },
        //新增项目字典
        add(val){
            this.bc = '1'
            this.tab = '1'
            this.type = '1'
            this.bj = '1'
            this.editIndex = '-1'
            console.log(val)
            this.data1.push({
                typeName: '',
                sort: '',
                relatingCodes: '',
                inspection: this.formValidate.projectCategory
            })              
        },
        /** 删除行 */
        delRow(val,index) {
            // this.data1.splice(idx, 1)
            let params = {
                "hospitalId": this.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    params.id= i.id
                    params.idel = 1
                    params.moldType = 0
                }
            })
            this.$axios
                .post(api.updateDictPage, params)
                .then(resp => {
                     console.log(params)
                    let ret = resp.data.object;
                    console.log(ret)
                })
                .catch(err => {
                    console.log(err);
                });
            this.getClassificationList()
        },
        //弹窗返回
        back(){
            if(this.modalStatus1){
                this.modalStatus1 = false
            }
        },
        // 分页器改变
        pageChange(index) {
            this.pageNo = index;
            if (this.xmmc) {
                this.getClassificationList(index, this.xmmc);
            } else {
                this.getClassificationList(index);
            }
        },
        pageChangexm(index) {
            this.pageNo = index;
            if (this.xmmc) {
                this.getHisPage(index, this.xmmc);
            } else {
                this.getHisPage(index);
            }
        },
    },
    watch: {
        'pageSize'(nv, ov) {
            this.getDoctorData(this.pageNo)
        },
        formValidate: {
            handler(n) {
                console.log(n);
            },
            deep: true
        }
    }
}
</script>
<style lang="less" scoped>
.edit{
    padding: 10px 30px;
    width: 100%;
    background: #ffffff;
    box-sizing: border-box;
    .main{
        margin-top:10px; 
        .infobox {
            margin: 10px auto;
            border: 1px solid #f0f0f0;
            box-shadow: 0 4px 3px #ebedf8;
            border-radius: 5px;
            margin-bottom: 20px;
            .title {
                font-size: 20px;
                padding-left: 15px;
                margin-bottom: 20px;
                color: #333;
                height: 40px;
                line-height: 40px;
                background: #ebedf8;         
            }
            .hongdian {
                margin-left: 10px;
            } 
            .tit{
                font-size:12px;
                color:#495060;
                margin-left: 20px;
            }         
            .footerList{
                width:100%;
                display:flex;
                flex: 1;
                flex-direction:row;
                margin-top: 10px;
                margin-bottom: 20px;
                justify-content: space-between;
                padding: 0 30px;
                .left,.right{
                    width: 49%;
                    border: 1px #ccc solid;
                    p{
                        text-align:center;
                        line-height: 45px;
                    }
                }
            }
        }
    }   
    Button{
        border-radius: 20px;
    }
}
</style>